package cn.liu.study.db.configurer;

import cn.liu.study.db.core.BodyReaderRequestWrapper;
import org.springframework.core.annotation.Order;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Order(1)
@WebFilter(filterName = "bodyRequestFilter", urlPatterns = "/*")
public class BodyRequestFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        BodyReaderRequestWrapper wrapper = new BodyReaderRequestWrapper(req);
        chain.doFilter(wrapper, response);
    }

    @Override
    public void destroy() {
    }
}
